package com.example.api.common.trace;

import org.slf4j.MDC;
import java.util.UUID;

public class TraceIdUtil {
    public static final String TRACE_ID = "traceId";
    
    public static String generateTraceId() {
        return UUID.randomUUID().toString().replace("-", "");
    }
    
    public static void setTraceId(String traceId) {
        MDC.put(TRACE_ID, traceId);
    }
    
    public static String getTraceId() {
        String traceId = MDC.get(TRACE_ID);
        if (traceId == null) {
            traceId = generateTraceId();
            setTraceId(traceId);
        }
        return traceId;
    }
    
    public static void clearTraceId() {
        MDC.remove(TRACE_ID);
    }
} 